package com.ymatou.iapi.livebuyer.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.DisableNotSpeakingBean;
import com.ymatou.iapi.livebuyer.service.DisableNotSpeakingCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.SpeakingNotAllowed;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.TestDataManager;
/**
*解除云通讯全局禁言
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DisableNotSpeaking{
	private static DisableNotSpeakingBean disablenotspeakingBean;
	private static DisableNotSpeakingCall disablenotspeakingCall;
	LiveRoomWapper LiveRoomWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("解除云通讯全局禁言");
	}

	@Before
	public void caseUp() {
		disablenotspeakingBean=new DisableNotSpeakingBean();
		disablenotspeakingCall=new DisableNotSpeakingCall();
		LiveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(disablenotspeakingCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DisableNotSpeaking_001() {
		Logger.start(true,"解除云通讯全局禁言成功");
		try {
			Integer userId=1;
			LiveRoomCallService.SetNotSpeeking(userId,100,0);
			Integer id=LiveRoomCallService.getSpeakingNotAllowedId(userId);
			DisableNotSpeakingBean disablenotspeakingBean=new DisableNotSpeakingBean();
			DisableNotSpeakingCall disablenotspeakingCall=new DisableNotSpeakingCall();
			disablenotspeakingBean.setNoSpeakingId(id);
			disablenotspeakingBean.setOperator("autotest2");
			disablenotspeakingBean.setUserId(userId);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("200", disablenotspeakingCall.getString("code"), "验证code");
			SpeakingNotAllowed SpeakingNotAllowed = LiveRoomWapper.selectSpeakingNotAllowed(userId,1).get(0);
			Logger.verifyEquals(disablenotspeakingBean.getOperator(), SpeakingNotAllowed.getOperator(), "验证Operator");
			Logger.verifyEquals(1, SpeakingNotAllowed.getState(), "验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableNotSpeaking_002() {
		Logger.start(true,"不输入userid失败");
		try {
			disablenotspeakingBean.setNoSpeakingId(1);
			disablenotspeakingBean.setOperator("autotest2");
//			disablenotspeakingBean.setUserId(userId);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("100", disablenotspeakingCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableNotSpeaking_003() {
		Logger.start(true,"不输入noSpeakingId失败");
		try {
//			disablenotspeakingBean.setNoSpeakingId(id);
			disablenotspeakingBean.setOperator("autotest2");
			disablenotspeakingBean.setUserId(1);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("100", disablenotspeakingCall.getString("code"), "验证code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableNotSpeaking_004() {
		Logger.start(true,"不输入operator失败");
		try {
			disablenotspeakingBean.setNoSpeakingId(1);
//			disablenotspeakingBean.setOperator("autotest2");
			disablenotspeakingBean.setUserId(1);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("100", disablenotspeakingCall.getString("code"), "验证code");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableNotSpeaking_005() {
		Logger.start(true,"重复解除失败");
		try {
			Integer userId=1;
			LiveRoomCallService.SetNotSpeeking(userId,100,0);
			Integer id=LiveRoomCallService.getSpeakingNotAllowedId(userId);
			DisableNotSpeakingBean disablenotspeakingBean=new DisableNotSpeakingBean();
			DisableNotSpeakingCall disablenotspeakingCall=new DisableNotSpeakingCall();
			disablenotspeakingBean.setNoSpeakingId(id);
			disablenotspeakingBean.setOperator("autotest2");
			disablenotspeakingBean.setUserId(userId);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();		
			disablenotspeakingCall.callService();		
			Logger.verifyEquals("400", disablenotspeakingCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableNotSpeaking_006() {
		Logger.start(true,"输入noSpeakingId和userid不匹配失败");
		try {
			disablenotspeakingBean.setNoSpeakingId(1);
			disablenotspeakingBean.setOperator("autotest2");
			disablenotspeakingBean.setUserId(101);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("400", disablenotspeakingCall.getString("code"), "验证code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DisableNotSpeaking_007() {
		Logger.start(true,"解除永久云通讯全局禁言成功");
		try {
			Integer userId=1;
			LiveRoomCallService.SetNotSpeeking(userId,0,0);
			Integer id=LiveRoomCallService.getSpeakingNotAllowedId(userId);
			DisableNotSpeakingBean disablenotspeakingBean=new DisableNotSpeakingBean();
			DisableNotSpeakingCall disablenotspeakingCall=new DisableNotSpeakingCall();
			disablenotspeakingBean.setNoSpeakingId(id);
			disablenotspeakingBean.setOperator("autotest2");
			disablenotspeakingBean.setUserId(userId);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("200", disablenotspeakingCall.getString("code"), "验证code");
			SpeakingNotAllowed SpeakingNotAllowed = LiveRoomWapper.selectSpeakingNotAllowed(userId,1).get(0);
			Logger.verifyEquals(disablenotspeakingBean.getOperator(), SpeakingNotAllowed.getOperator(), "验证Operator");
			Logger.verifyEquals(1, SpeakingNotAllowed.getState(), "验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DisableNotSpeaking_008() {
		Logger.start(true,"解除云通讯全局禁言成功,操作人20字符");
		try {
			Integer userId=1;
			LiveRoomCallService.SetNotSpeeking(userId,100,0);
			Integer id=LiveRoomCallService.getSpeakingNotAllowedId(userId);
			DisableNotSpeakingBean disablenotspeakingBean=new DisableNotSpeakingBean();
			DisableNotSpeakingCall disablenotspeakingCall=new DisableNotSpeakingCall();
			disablenotspeakingBean.setNoSpeakingId(id);
			disablenotspeakingBean.setOperator("12345678901234567890");
			disablenotspeakingBean.setUserId(userId);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("200", disablenotspeakingCall.getString("code"), "验证code");
			SpeakingNotAllowed SpeakingNotAllowed = LiveRoomWapper.selectSpeakingNotAllowed(userId,1).get(0);
			Logger.verifyEquals(disablenotspeakingBean.getOperator(), SpeakingNotAllowed.getOperator(), "验证Operator");
			Logger.verifyEquals(1, SpeakingNotAllowed.getState(), "验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DisableNotSpeaking_009() {
		Logger.start(true,"操作人超出20字符,解除云通讯全局禁言失败");
		try {
			Integer userId=1;
			LiveRoomCallService.SetNotSpeeking(userId,100,0);
			Integer id=LiveRoomCallService.getSpeakingNotAllowedId(userId);
			DisableNotSpeakingBean disablenotspeakingBean=new DisableNotSpeakingBean();
			DisableNotSpeakingCall disablenotspeakingCall=new DisableNotSpeakingCall();
			disablenotspeakingBean.setNoSpeakingId(id);
			disablenotspeakingBean.setOperator("123456789012345678901");
			disablenotspeakingBean.setUserId(userId);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("100", disablenotspeakingCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DisableNotSpeaking_010() {
		Logger.start(true,"解除云通讯直播禁言成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int liveid = livedto.getId();
			//需要tx云存在的用户
			Integer userId = 24636166;
			LiveRoomCallService.SetNotSpeeking(userId,100,liveid);
			Integer id=LiveRoomCallService.getSpeakingNotAllowedId(userId);
			DisableNotSpeakingBean disablenotspeakingBean=new DisableNotSpeakingBean();
			DisableNotSpeakingCall disablenotspeakingCall=new DisableNotSpeakingCall();
			disablenotspeakingBean.setNoSpeakingId(id);
			disablenotspeakingBean.setOperator("autotest2");
			disablenotspeakingBean.setUserId(userId);
			disablenotspeakingCall.setData(disablenotspeakingBean);
			disablenotspeakingCall.callService();			
			Logger.verifyEquals("200", disablenotspeakingCall.getString("code"), "验证code");
			SpeakingNotAllowed SpeakingNotAllowed = LiveRoomWapper.selectSpeakingNotAllowed(userId,1).get(0);
			Logger.verifyEquals(disablenotspeakingBean.getOperator(), SpeakingNotAllowed.getOperator(), "验证Operator");
			Logger.verifyEquals(1, SpeakingNotAllowed.getState(), "验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}